<?php 
include("header.php");
$db = new db();
$status = $db->connect();
if($status){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>สัตวแพทย์</title>
<link href="style/style.css" rel="stylesheet"  type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main_resize">
    <div class="header">
      <div class="logo">
        <h1><a href="index.html"><span>สำนักงาน</span>ปศุสัตว์<small>จังหวัดลำปาง</small></a></h1>
      </div><!-- end logo -->
    </div><!-- end header -->
    <div class="content">
      <div class="content_bg">
        <div class="menu_nav">
          <ul>
            <li><a href="Login.html">หน้าแรก</a></li>
            <li><a href="CheckData.php">ขอใบรับรอง</a></li>
            <li><a href="Map.php">พิกัดจุดฟาร์ม</a></li>
            <li class="active"><a href="EditOwner.php">จัดการข้อมูลหลัก</a></li>
            <li><a href="Report.php">รายงาน</a></li>
            <li><a href="#">แจ้งเตือน</a></li>
          </ul>
        </div><!-- end menu_nav -->
        <div class="hbg"><img src="images/header_images.jpg" width="915" height="286" alt="header images" /></div><!-- end hbg -->
        <div class="mainbar">
          <div class="article">
            <h2><span>สัตวแพทย์</span></h2>
            <div class="clr"></div><!-- end clr -->
            		<?php
if($_REQUEST['do'] == "frmedit")
{
	$sql = "SELECT * FROM veterinary WHERE Veterinary_ID = ".$_REQUEST['id'];
	$result= mysql_query($sql);
	$arr = mysql_fetch_array($result);
 	$id = $_REQUEST['id'];
?>
<form method="post" action="EditVeterinary_action.php?do=edit">
	
<table width="600" border="0" align="center" cellpadding="2" cellspacing="0">
    	<tr>
        	<td align="right">ชื่อ : </td>
            <td><input type="text" name="name" value="<?=$arr['Name'];?>" /></td>
        </tr>
        <tr>
        	<td align="right">เลขที่ : </td>
            <td><input type="text" name="addr"  pattern="\d+(\/\d{1,2})?" value="<?=$arr['Address'];?>" /></td>
        </tr>
        <tr>
        	<td align="right">หมู่ : </td>
            <td><input type="number" name="moo" min="1" max="99" value="<?=$arr['Moo'];?>" /></td> 
        </tr>
        <tr>
        	<td align="right">ตำบล : </td>
            <td>
            	<select name="district">
                	<? 
						$dis = "SELECT * FROM district"; 
						mysql_query("SET NAMES utf8");
						$dis_re = mysql_query($dis); 
						while($d_arr = mysql_fetch_array($dis_re))
						{
							if($arr['ID_District']==$d_arr['District_ID']){
								echo "<option value='".$d_arr['District_ID']."' selected>".$d_arr['Name']."</option>";
							}else{
								echo "<option value=".$d_arr['District_ID'].">".$d_arr['Name']."</option>";
							}
						}
					?>
                </select>
            </td>
        </tr>
        <tr>
        	<td align="right">โทรศัพท์ : </td>
            <td><input type="text" name="tel" pattern="\d{1}-\d{4}-\d{4}"  step="9" maxlength="11" size="11" value="<?=$arr['Tel'];?>"/> </td>
        </tr>
        <tr>
        	<td align="right">มือถือ : </td>
            <td><input type="text" name="phone" pattern="\d{2}-\d{4}-\d{4}"  step="10" maxlength="12" size="12" value="<?=$arr['Phone'];?>"/></td>
        </tr>
        <tr>
        	<td align="right">โทรสาร : </td>
            <td><input type="text" name="fax" pattern="\d{1}-\d{4}-\d{4}"  step="9" maxlength="11" size="11" value="<?=$arr['Fax'];?>"/></td> 
        </tr>
        <tr>
            <td>&nbsp;</td>
           
            <? 
			if($arr['Permit'] == 1){
            	echo "<td><input type='radio' name='Permit' id='Permit' value='1' checked='checked' /><label  >ใบอนุญาตสัตวแพทย์ผู้ควบคุมฟาร์ม<br/> 
                 &nbsp;&nbsp;เลขที่ : <input type='text' name='NumPermit' id='NumPermit' value=".$arr['No_Permit']."/><br/>
                 &nbsp;&nbsp;วันหมดอายุ : <input type='date' name='ExpPermit' id='ExpPermit' value=".$arr['Exp_Permit']."/><br/>
             </td>";
			}else{
				echo "<td><input type='radio' name='Permit' id='Permit' value='1' /><label  >ใบอนุญาตสัตวแพทย์ผู้ควบคุมฟาร์ม <br/>
                  &nbsp;&nbsp;เลขที่ : <input type='text' name='NumPermit' id='NumPermit' /><br/>
                  &nbsp;&nbsp;วันหมดอายุ : <input type='date' name='ExpPermit' id='ExpPermit' /><br/>
             </td>";
			}
			 ?>
        </tr>
        <tr>
        	<td colspan="2" align="center">
            <input type="hidden" name="id_edit" value="<?=$arr['Veterinary_ID'];?>">
            <input type="submit" value="ยืนยัน" />
            </td>
        </tr>
         
    </table>
</form>
<?php
}elseif($_REQUEST['do'] == "edit"){
	$name = $_REQUEST['name'];
	$addr = $_REQUEST['addr'];
	$moo = $_REQUEST['moo'];
	$district = $_REQUEST['district'];
	$tel = $_REQUEST['tel'];
	$phone = $_REQUEST['phone'];
	$fax = $_REQUEST['fax'];
	$Permit = "";
	if($_REQUEST['Permit'] != ""){
		$Permit = $_REQUEST['Permit'];
	}
	$NumPermit = "";
	$ExpPermit = "";
	if($Permit == 1){ 
		$NumPermit = $_REQUEST['NumPermit'];
		$ExpPermit = $_REQUEST['ExpPermit'];
	}
	$id = $_REQUEST['id_edit'];
	$query_status = $db->update("veterinary",
									"Name,Address,Moo,ID_District,Tel,Phone,Fax,Permit,No_Permit,Exp_Permit",
									"'$name','$addr',$moo,'$district','$tel','$phone','$fax',$Permit,'$NumPermit','$ExpPermit'",
									" WHERE Veterinary_ID = $id"); 
									
	if($query_status == 1){
		echo "อัพเดตข้อมูลเรียบร้อย !!!";
		echo "<meta http-equiv='refresh' content='3;url=EditVeterinary.php'>";
	}else{
		echo $query_status;
	}
}
?>
                
            <div class="clr"></div><!-- end clr -->
          </div><!-- end article -->
        </div><!-- end mainbar -->
        <div class="sidebar">
          <div class="gadget">
            <div class="search">
              <form method="get" id="search" action="">
                <span>
                <input type="text" value="Search..." name="s" id="s" />
                <input name="searchsubmit" type="image" src="images/search.gif" value="Go" id="searchsubmit" class="btn"  />
                </span>
              </form>
              <!--/searchform -->
              <div class="clr"></div>
            </div><!-- end search -->
          </div><!-- end gadget -->
          <div class="gadget">
            <h2 class="star"><span>เมนู</span> ย่อย</h2>
            <div class="clr"></div>
            <ul class="sb_menu">
              <li><a href="EditOwner.php">เจ้าของฟาร์ม</a></li>
              <li><a href="EditFarm.php">ฟาร์ม</a></li>
              <li><a href="EditPaper.php">เอกสาร</a></li>
              <li><a href="EditVeterinary.php">สัตวแพทย์</a></li>
              <li class="active"><a href="EditAnimalHusbandman.php">สัตวบาล</a></li>
              <li><a href="EditPhoto.php">รูปภาพ</a></li>
              <li><a href="EditUser.php">ผู้ใช้ระบบ</a></li>
            </ul><!-- end sb_menu -->
          </div><!-- end gadget -->
        </div><!-- end sidebar -->
        <div class="clr"></div>
      </div><!-- end content_bg -->
      <div class="fbg"><!-- end fbg_resize -->
      </div><!-- end fbg -->
    </div><!-- end content -->
    <div class="footer">
      <div class="footer_resize">
        <p class="lf">สำนักงานปศุสัตว์จังหวัดลำปาง Tel 0-5421-8127 Fax. 0-5421-7550 <a href="http://dld.go.th/pvlo_lpg/th/">MyWebSite</a>.</p>
        <p class="rf">E-mail: pvlo_lpg@dld.go.th <a href="http://www.hotmail.com/">ติดต่อ</a></p>
        <div class="clr"></div>
      </div><!-- end footer_resize -->
    </div><!-- end footer -->
  </div><!-- end main_resize -->
</div><!-- end main -->
</body>
</html>
<?php
}
else{
	echo "ไม่สามารถติดต่อฐานข้อมูลได้ !!!!";
}
?>

